home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form FindDlg
- Caption = "Find"
- ClientHeight = 2025
- ClientLeft = 375
- ClientTop = 645
- ClientWidth = 7185
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 2430
- Icon = "FindDlg.frx":0000
- Left = 315
- LinkTopic = "Form1"
- ScaleHeight = 2025
- ScaleWidth = 7185
- Top = 300
- Width = 7305
- Begin VB.TextBox FindText
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 375
- Left = 120
- TabIndex = 9
- Top = 480
- Width = 5415
- End
- Begin VB.CommandButton CloseButton
- BackColor = &H80000005&
- Caption = "Close"
- Height = 375
- Left = 5880
- TabIndex = 8
- Top = 720
- Width = 1215
- End
- Begin VB.CommandButton FindButton
- BackColor = &H80000005&
- Caption = "Find Next"
- Height = 375
- Left = 5880
- TabIndex = 7
- Top = 120
- Width = 1215
- End
- Begin VB.CheckBox EntireCell
- Caption = "Entire Cells Only"
- Height = 255
- Left = 3120
- TabIndex = 6
- Top = 1440
- Width = 1815
- End
- Begin VB.CheckBox MatchCase
- Caption = "Match Case"
- Height = 255
- Left = 3120
- TabIndex = 5
- Top = 1080
- Width = 1575
- End
- Begin VB.ComboBox LookCombo
- Height = 315
- Left = 1320
- Style = 2 'Dropdown List
- TabIndex = 1
- Top = 1560
- Width = 1455
- End
- Begin VB.ComboBox SearchCombo
- Height = 315
- Left = 1320
- Style = 2 'Dropdown List
- TabIndex = 0
- Top = 1080
- Width = 1455
- End
- Begin VB.Label Label3
- Caption = "Look In:"
- Height = 255
- Left = 240
- TabIndex = 4
- Top = 1560
- Width = 975
- End
- Begin VB.Label Label2
- Caption = "Search:"
- Height = 255
- Left = 240
- TabIndex = 3
- Top = 1080
- Width = 975
- End
- Begin VB.Label Label1
- Caption = "Find What"
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 0
- weight = 700
- size = 9.75
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- Height = 255
- Left = 120
- TabIndex = 2
- Top = 120
- Width = 2055
- End
- Attribute VB_Name = "FindDlg"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Private Sub CloseButton_Click()
- FindDlg.Hide
- End Sub
- Private Sub FindButton_Click()
- Call FindData
- End Sub
- Private Sub FindData()
- Dim LastRow%, LastCol%
- Dim TheRow%, TheCol%, TheType%
- Dim StartRow%, StartCol%
- Dim X1&, Y1&, X2&, Y2&
- Dim CellVisible%
- Dim ssError%
- '' This procedure searches the worksheet for the specified
- '' text. It only searches the current page (tab).
- If SSIsActiveForm() Then
- TheRow = MainFrame.ActiveForm.SS.Row
- TheCol = MainFrame.ActiveForm.SS.Col
- StartRow = TheRow
- StartCol = TheCol
- LastRow = MainFrame.ActiveForm.SS.LastRow
- LastCol = MainFrame.ActiveForm.SS.LastCol
- '' Make sure there is data in the worksheet
- If LastRow = 0 Then
- MsgBox "No data in the spreadsheet."
- MainFrame.ActiveForm.SS.SetFocus
- Exit Sub
- End If
- '' Search the worksheet by rows
- If SearchCombo.ListIndex = 0 Then
- TheCol = TheCol + 1 ' Skip the column we are in
- '' Keep cycling through the rows one at a time
- Do
- '' Get the last column in this row (so we don't search all columns)
- LastCol = MainFrame.ActiveForm.SS.LastColForRow(TheRow)
- '' Search all the cells from the current one to the last one in this row
- Do While TheCol <= LastCol
- '' See if we searched the whole worksheet
- If TheRow = StartRow And TheCol = StartCol Then
- MsgBox "Data not found."
- MainFrame.ActiveForm.SS.SetFocus
- Exit Sub
- End If
- '' Check this cell for a match
- TheType = MainFrame.ActiveForm.SS.TypeRC(TheRow, TheCol)
- If MatchCell(TheRow, TheCol, TheType) Then
- '' Data was found
- MainFrame.ActiveForm.SS.SetFocus
- '' If cell is not visible then move the sheet so it is in the upper left
- MainFrame.ActiveForm.SS.RangeToTwips TheRow, TheCol, TheRow, TheCol, X1, Y1, X2, Y2, CellVisible
- If CellVisible <> 1 Then
- MainFrame.ActiveForm.SS.TopRow = IIf(TheRow > 1, TheRow - 1, 1)
- MainFrame.ActiveForm.SS.LeftCol = IIf(TheCol > 1, TheCol - 1, 1)
- End If
- Exit Sub
- End If
- TheCol = TheCol + 1
- Loop
- '' Next Row - If we are at the end then start back at the top
- TheCol = 1
- TheRow = IIf(TheRow < LastRow, TheRow + 1, 1)
- Loop
- Else '' Search by columns
- TheRow = TheRow + 1 '' Skip the row we are in
- '' Keep cycling through the columns one at a time
- Do
- '' Search all the cells from the current one to the last one in this column
- Do While TheRow <= LastRow
- '' See if we searched the whole worksheet
- If TheRow = StartRow And TheCol = StartCol Then
- MsgBox "Data not found."
- MainFrame.ActiveForm.SS.SetFocus
- Exit Sub
- End If
- '' Check this cell for a match
- TheType = MainFrame.ActiveForm.SS.TypeRC(TheRow, TheCol)
- If MatchCell(TheRow, TheCol, TheType) Then
- MainFrame.ActiveForm.SS.SetFocus
- '' If cell is not visible then move the sheet so it is in the upper left
- MainFrame.ActiveForm.SS.RangeToTwips TheRow, TheCol, TheRow, TheCol, X1, Y1, X2, Y2, CellVisible
- If CellVisible <> 1 Then
- MainFrame.ActiveForm.SS.TopRow = IIf(TheRow > 1, TheRow - 1, 1)
- MainFrame.ActiveForm.SS.LeftCol = IIf(TheCol > 1, TheCol - 1, 1)
- End If
- Exit Sub
- End If
- TheRow = TheRow + 1
- Loop
- '' Next Column - If we are at the end then start back at the left
- TheRow = 1
- TheCol = IIf(TheCol < LastCol, TheCol + 1, 1)
- Loop
- End If
- End If
- End Sub
- Private Sub FindText_KeyPress(KeyAscii As Integer)
- If KeyAscii = 13 Then '' Enter has been pressed
- Call FindData
- KeyAscii = 0
- End If
- End Sub
- Private Sub Form_GotFocus()
- FindText.SetFocus
- End Sub
- Private Sub Form_Load()
- SearchCombo.AddItem "By Rows" '' Initialize the data in the combo
- SearchCombo.AddItem "By Columns" '' boxes for the find dialog box
- SearchCombo.ListIndex = 0 '' The inital settings will be to
- '' search by rows through text
- LookCombo.AddItem "Text"
- LookCombo.AddItem "Numbers"
- LookCombo.ListIndex = 0
- End Sub
- Private Function MatchCell%(TheRow%, TheCol%, TheType%)
- '' This function returns a value telling if the data to be found and
- '' the data in the current row and column match one another
- Dim ssError%
- '' Test number cells or formulas returning numbers
- '' Test to two decimal places
- If LookCombo.ListIndex = 1 And Abs(TheType) = 1 Then
- MainFrame.ActiveForm.SS.Row = TheRow
- MainFrame.ActiveForm.SS.Col = TheCol
- If Int((MainFrame.ActiveForm.SS.Number + 0.001) * 100) = Int((Val(FindText.TEXT) + 0.001) * 100) Then
- MatchCell = True
- Exit Function
- End If
- '' Test Text or text results of formulas
- ElseIf LookCombo.ListIndex = 0 And Abs(TheType) = 2 Then
- MainFrame.ActiveForm.SS.Row = TheRow
- MainFrame.ActiveForm.SS.Col = TheCol
- '' Match any part of the cell
- If EntireCell.VALUE = 0 Then
- If InStr(1, MainFrame.ActiveForm.SS.TEXT, FindText.TEXT, IIf(MatchCase.VALUE = 0, 1, 0)) Then
- MatchCell = True
- Exit Function
- End If
- '' Match the whole cell
- Else
- '' Match case exactly
- If MatchCase.VALUE = 1 Then
- If MainFrame.ActiveForm.SS.TEXT = FindText.TEXT Then
- MatchCell = True
- Exit Function
- End If
- '' Match regardless of case
- Else
- If UCase(MainFrame.ActiveForm.SS.TEXT) = UCase(FindText.TEXT) Then
- MatchCell = True
- Exit Function
- End If
- End If
- End If
- End If
- MatchCell = False
- End Function
-